%%%-----------------------------------
%%% @Module  : pt_23
%%% @Author  : xws
%%% @Created : 2016.10.9
%%% @Description: 
%%%-----------------------------------
-module(pt_23).
-export([read/2, write/2]).
-include("common.hrl").
-include("proto_23_task.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%% 23000 请求玩家任务数据
read(23000, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_task_data, Bin), 
    #c2s_get_task_data{player_id = PlayerId} = ClientData,
    {ok, [PlayerId]};

%% 23002 领取任务奖励
read(23002, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_pick_task_award, Bin),    
    #c2s_pick_task_award{task_id = TaskId} = ClientData,
    {ok, [TaskId]};

%% 23003 刷新当前挑战任务
read(23003, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_refresh_now_challenge_task, Bin),    
    [_|Data] = erlang:tuple_to_list(ClientData),
    {ok, Data};

%% 23004 领取N日任务额外奖励
read(23004, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_dayN_task_award, Bin),    
    [_|Data] = erlang:tuple_to_list(ClientData),
    {ok, Data};

%% 23005 领取活跃度奖励
read(23005, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_get_liveness_award, Bin),    
    [_|Data] = erlang:tuple_to_list(ClientData),
    {ok, Data};

%% 23008 牌局红包任务领取记录
read(23008, Bin) ->
    {ClientData, _} = proto_read:unpack(c2s_poke_redpack_task_hisroty, Bin),    
    #c2s_poke_redpack_task_hisroty{room_level = RoomLevel} = ClientData,
    {ok, [RoomLevel]};



read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_23 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%
%% 23000 请求玩家任务数据
write(23000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_task_data, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23000, ServerData)};

%% 23001 推送玩家任务状态
write(23001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_notify_task_state, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23001, ServerData)};

%% 23002 领取任务奖励
write(23002, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_pick_task_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23002, ServerData)};

%% 23003 刷新当前挑战任务
write(23003, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_refresh_now_challenge_task, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23003, ServerData)};

%% 23004 领取N日任务额外奖励
write(23004, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_dayN_task_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23004, ServerData)};

%% 23005 领取活跃度奖励
write(23005, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_liveness_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23005, ServerData)};

%% 23006 推送玩家任务状态
write(23006, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_refresh_poke_drow_task, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23006, ServerData)};

%% 23007 推送玩家完成牌局循环任务
write(23007, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_pick_poke_cyc_task_award, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23007, ServerData)};

%% 23008 牌局红包任务领取记录
write(23008, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_redpack_task_hisroty, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23008, ServerData)};

%% 23009 广播牌局红包任务领取记录
write(23009, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_poke_redpack_info, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(23009, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_23 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.
